//
//  JddAlertView.m
//  PlayBall
//
//  Created by Huawen Liu on 12-7-20.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddAlertView.h"
#import "JddUserProfile.h"
#import "JddViewControllerManager.h"

@implementation JddAlertView
@synthesize jddalert;
@synthesize typestring;
@synthesize lssueString;
@synthesize type;
@synthesize message;
@synthesize delegate;
@synthesize button1;
@synthesize button2;
@synthesize label1;
@synthesize label2;
@synthesize label3;
@synthesize label4;
@synthesize label5;
@synthesize label6;
@synthesize label7;
@synthesize moneylable, faMoney;
@synthesize fromview;
GET_INSTANCE_VIEW_IMPLEMENT(JddAlertView)


-(IBAction)selectButton1:(id)sender{
    [self dismissAnimated:YES];
    switch (type) {
        case 0:
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_SELECT_RECHARGE_WAY 
                                                                 fromController:fromview 
                                                                     withObject:nil 
                                                                    withObject2:nil];
            break;
        case 1:
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOTTERY_HALL 
                                                                 fromController:nil
                                                                     withObject:nil 
                                                                    withObject2:nil];
            break;
        default:
            break;
    }
    [self dismissAnimated:YES];
}

-(IBAction)selectButton2:(id)sender{
    [self dismissAnimated:YES];
    if (type == 1) {
         [self lottery_open];
    }
    [self dismissAnimated:YES];
}

-(void)lottery_open
{
    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_BUY_HISTORY
                                                         fromController:fromview
                                                             withObject:nil
                                                            withObject2:nil];
}
-(void)alertBuyMessage:(NSString*)Message{
    type =1;
    label3.hidden = NO;
    label4.hidden = NO;
    label7.hidden = NO;
    message.hidden = YES;
    label6.text = @"投注成功";
    label3.text = [NSString stringWithFormat:@"方案金额：%@",moneylable];
    label4.text = [NSString stringWithFormat:@"方案编号：%@",lssueString];
    [label3 setTextAlignment:NSTextAlignmentLeft];
        [label4 setTextAlignment:NSTextAlignmentLeft];
    label7.text = [NSString stringWithFormat:@"发起%@购买方案",Message];
    [self loadContentView ];
    [self show];
}


-(void)alertFaQiCoBuyMessage:(NSString*)msgTitle totalMoney:(int) money rengouMoeny:(int)rgMoney baodiMoney:(int)bdMoney{
    type =1;
    label3.hidden = NO;
    label4.hidden = NO;
    label7.hidden = NO;
    message.hidden = YES;
    label6.text = @"投注成功";
    label3.text = [NSString stringWithFormat:@"方案金额：%d彩豆",money];
    label4.text = [NSString stringWithFormat:@"我的认购：%d彩豆",rgMoney];
    label5.text = [NSString stringWithFormat:@"我的保底：%d彩豆",bdMoney];
    [label3 setTextAlignment:NSTextAlignmentCenter];
        [label4 setTextAlignment:NSTextAlignmentCenter];
        [label5 setTextAlignment:NSTextAlignmentCenter];
    label7.text = msgTitle;
    [self loadContentView ];
    [self show];
}

-(void)alertMessage:(NSString*)Message{
    type =1;
    message.text = Message;
    if ([Message rangeOfString:@"余额不足"].location != NSNotFound) {
        type =0;
        label1.text = @"充值";
        label2.text = @"取消";
        label6.text = @"玩球网";
        message.hidden = NO;
        [self loadContentView ];
        [self show];
    }else if ([Message rangeOfString:@"成功"].location != NSNotFound) {
        [JddCommonFunction setWaitingViewHidden:NO fromController:self.fromview];
        label6.text = Message;
        JddQueryUserInfoOperation *operation = [[JddQueryUserInfoOperation alloc] init];
        operation.delegate = self;
        [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
    }else{
        [self loadContentView];
        [self show];
    }
}

- (void)QueryUserInfoOperationResult:(NSData *)result{
    [JddCommonFunction setWaitingViewHidden:YES fromController:self.fromview];
    if (result) {
        if ([JddDataParser parseUserInfoResult:result]) {
            label3.hidden = NO;
            label4.hidden = NO;
            label5.hidden = NO;
            label7.hidden = NO;
            NSString *string1= [NSString stringWithFormat:@"第%@期",lssueString];
            if ([lssueString length]>0) {
                string1= [NSString stringWithFormat:@"第%@期",lssueString];
            }else {
                string1 = @"";
            }
            label3.text = [NSString stringWithFormat:@"方案金额：%@",moneylable];
            label7.text = [NSString stringWithFormat:@"发起%@%@购买方案",typestring,string1];
            label4.text = [NSString stringWithFormat:@"认购金额：%@",moneylable];
            label5.text = [NSString stringWithFormat:@"账户余额：%@彩豆",[JddUserProfile sharedInstance].balance];
            message.hidden = YES;
        }
    }
    [self loadContentView ];
    [self show];
}

- (void)loadContentView{
    _contentView = [JddAlertView getInstanceView];
}

@end
